
package com.jf.cloud.supplier.controller.admin;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.common.util.ExcelUtil;
import com.jf.cloud.supplier.bo.mongo.MongoSupplierWalletLogBO;
import com.jf.cloud.supplier.dto.SupplierWalletLogSearchDTO;
import com.jf.cloud.supplier.service.SupplierWalletLogService;
import com.jf.cloud.supplier.service.SupplierWalletService;
import com.jf.cloud.supplier.vo.SupplierWalletLogExcelVO;
import com.jf.cloud.supplier.vo.SupplierWalletVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店铺钱包日志
 *
 * @author zz
 * @date 2021/6/8 19:46
 */
@RestController("adminSupplierWalletController")
@RequestMapping("/mp/supplier_wallet")
@Tag(name = "admin-供应商店铺钱包")
public class SupplierWalletController {

    @Autowired
    private SupplierWalletLogService supplierWalletLogService;

    @Autowired
    private SupplierWalletService supplierWalletService;

    @GetMapping("/page")
    @Operation(summary = "分页查询" , description = "分页查询")
    public ServerResponseEntity<PageVO<MongoSupplierWalletLogBO>> getSupplierWalletLogPage(PageDTO pageDTO, @ParameterObject SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        supplierWalletLogSearchDTO.setSupplierId(AuthUserContext.get().getTenantId());
        PageVO<MongoSupplierWalletLogBO> page = supplierWalletLogService.pageByParam(pageDTO, supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(page);
    }

    @GetMapping("/get_all_supplier_wallet")
    @Operation(summary = "查看所有供应商钱包总信息")
    public ServerResponseEntity<SupplierWalletVO> getAllSupplierWalletVoBySupplierId(@ParameterObject SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        SupplierWalletVO supplierWallet = supplierWalletService.getAllSupplier(supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(supplierWallet);
    }

    @GetMapping("/page_supplier_wallet_by_time")
    @Operation(summary = "分页查看供应商钱包总信息")
    public ServerResponseEntity<PageVO<SupplierWalletVO>> pageSupplierWalletByTime(PageDTO pageDTO, @ParameterObject SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        PageVO<SupplierWalletVO> pageSupplierWalletByTime = supplierWalletService.pageSupplierWalletByTime(pageDTO, supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(pageSupplierWalletByTime);
    }

    @GetMapping("/page_all_supplier")
    @Operation(summary = "查看所有供应商店铺的钱包记录日志")
    public ServerResponseEntity<PageVO<MongoSupplierWalletLogBO>> getAllSupplierWalletLogPage(PageDTO pageDTO, @ParameterObject SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        PageVO<MongoSupplierWalletLogBO> page = supplierWalletLogService.pageAllSupplier(pageDTO, supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(page);
    }

    @GetMapping("/get_supplier_wallet_log_form")
    @Operation(summary = "导出供应商结算报表" , description = "导出供应商结算报表")
    public ServerResponseEntity<Void> getSupplierWalletLogForm(HttpServletResponse response, @ParameterObject SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        List<SupplierWalletLogExcelVO> list = supplierWalletLogService.listSupplierWalletLogExcel(supplierWalletLogSearchDTO);
        ExcelUtil.soleExcel(response, list, SupplierWalletLogExcelVO.EXCEL_NAME, SupplierWalletLogExcelVO.MERGE_ROW_INDEX, SupplierWalletLogExcelVO.MERGE_COLUMN_INDEX,  SupplierWalletLogExcelVO.class);
        return ServerResponseEntity.success();
    }

    @GetMapping("/get_supplier_wallet")
    @Operation(summary = "查看店铺钱包信息" , description = "根据店铺id查看店铺钱包信息")
    public ServerResponseEntity<SupplierWalletVO> getSupplierWalletVoBySupplierId() {
        SupplierWalletVO supplierWallet = supplierWalletService.getBySupplierId(AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success(supplierWallet);
    }
}
